package com.spring.shops.service.impl;

import com.spring.shops.dao.TzCategoryMapper;
import com.spring.shops.model.entity.TzCategory;
import com.spring.shops.model.result.ServerResponseEntityVoid;
import com.spring.shops.model.vo.ProdCategoryVO;
import com.spring.shops.service.ProdCategoryService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ProdCategoryServiceImpl implements ProdCategoryService {
    @Autowired
    private TzCategoryMapper mapper;
    /**
     * 列出所有的分类
     * @return
     */
    @Override
    public ServerResponseEntityVoid<List<ProdCategoryVO>> listCategory() {
       List<TzCategory> CategoryList=mapper.listCategory();
       List<ProdCategoryVO> CategoryListVO=new ArrayList<>();
       //进行属性拷贝
        for (TzCategory tzCategory : CategoryList) {
            ProdCategoryVO prodCategoryVO = new ProdCategoryVO();
            BeanUtils.copyProperties(tzCategory,prodCategoryVO);
            CategoryListVO.add(prodCategoryVO);
        }
        return ServerResponseEntityVoid.success(CategoryListVO);
    }
}
